package com.it.park.rms.tag;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.it.park.rms.common.util.empty.EmptyUtil;
import com.it.park.rms.common.util.empty.StringUtil;

public class ButtonTag extends TagSupport  {

	private static final long serialVersionUID = 1L;
	private String operationId; // 对应Attribute,加上set方法。
	private String name;      // 按钮名（添加）
	private String clazz;     // 样式
	private String iconCls;   // 图标
	private String onClick;   // 点击事件
	
	
	public String getOperationId() {
		return operationId;
	}


	public void setOperationId(String operationId) {
		this.operationId = operationId;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getClazz() {
		return clazz;
	}


	public void setClazz(String clazz) {
		this.clazz = clazz;
	}


	public String getIconCls() {
		return iconCls;
	}


	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}


	public String getOnClick() {
		return onClick;
	}


	public void setOnClick(String onClick) {
		this.onClick = onClick;
	}


	@Override
	public int doStartTag() throws JspException {
		HttpSession session = pageContext.getSession();
//		String currentOperationIds = (String) session.getAttribute("buttonList");
		List<String> buttonList = (List<String>) session.getAttribute("buttonList");
		if(EmptyUtil.isNotEmpty(buttonList) && EmptyUtil.isExistStr(buttonList, operationId)){
			StringBuilder builder = new StringBuilder();
			builder.append("<a href=\"javascript:");
			builder.append(onClick + "\"");
			builder.append("class=\""+clazz+"\"");
			builder.append("iconCls=\""+iconCls+"\"");
			builder.append("plain=\"true\" >");
			builder.append(name +"</a>");
			try {
					pageContext.getOut().write(builder.toString());
				return EVAL_PAGE;
			} catch (IOException e) {
				return SKIP_BODY;
			}
		}else{
			return SKIP_BODY;
		}
	}
	
	
}
